<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport"
    content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>


<body>
  <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
  <script>
    function delay() {
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve(22)
        })
      })
    }
    let p = delay().then((res) => {
      console.log('555')
    })

    // async await的作用：可以让我们像写同步代码一样执行我们的异步代码
    //   语法糖
    async function xxx() {
      console.log('top')
      const result = await delay()
      console.log(result)
      const result1 = await delay()
      console.log(result1)
      const result2 = await delay()
      console.log(result2)
      console.log('bottom')
      // console.log('6666')
    }
    //   xxx()

    async function chatRobot() {
      const res = await axios({
        url: 'http://ajax-api.itheima.net/api/robot?spoken=你饿不饿',
      })
      console.log(res)
      const res1 = await axios({
        url: 'http://ajax-api.itheima.net/api/robot?spoken=王苏琪是否是王苏琪',
      })
      console.log(res1)
      const res2 = await axios({
        url: 'http://ajax-api.itheima.net/api/robot?spoken=我给你买包子',
      })
      console.log(res2)
    }
    chatRobot()
  </script>
</body>

</html>